package com.ymatou.iapi.productcategory.service;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.productcategory.parameter.BrandDto;
import com.ymatou.iapi.productcategory.parameter.CategoryTagInfo;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

public class GetCategoryTagInfoCall extends YmatouBaseCall {
	private static String opurl = "api/admin/GetCategoryTagInfo";

	public GetCategoryTagInfoCall() {
		super(EnvSetup.getSystemUrl("productcategory_iapi"), opurl, "GET", "PARAM");
	}

	/**
	 * @param domain
	 *            EnvSetup.getSystemUrl("productcategory_iapi") or
	 *            EnvSetup.getSystemUrl("productcategory_api") 用于新旧站点
	 */
	public GetCategoryTagInfoCall(String domain) {
		super(domain, opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	public List<CategoryTagInfo> getCategoryTagInfoList() {
//		return getJsonObject().getAsJsonObject("Data").getAsJsonArray("CategoryTagInfoList").toString();
		ArrayList<CategoryTagInfo> result =new ArrayList<CategoryTagInfo>();
		try {
			result = (ArrayList<CategoryTagInfo>) new Gson().fromJson(getJsonObject().get("Data").getAsJsonObject().getAsJsonArray("CategoryTagInfoList").toString(), new TypeToken<ArrayList<CategoryTagInfo>>() {}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
